package com.example.zuul.filter;

import com.netflix.zuul.ZuulFilter;
import com.netflix.zuul.exception.ZuulException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.netflix.zuul.filters.support.FilterConstants;
import org.springframework.stereotype.Component;

/**
 * @author HuaLX
 * @description:
 * @time: 2022-01-11 18:33
 **/
@Component
@Slf4j
public class AuthFilter extends ZuulFilter {

    @Override
    public String filterType() {
        // 前置过滤器
        return FilterConstants.PRE_TYPE;
    }

    @Override
    public int filterOrder() {
        return 0;
    }

    @Override
    public boolean shouldFilter() {
        return true;
    }

    @Override
    public Object run() throws ZuulException {
        log.info("进入zuul过滤器");
//        RequestContext currentContext = RequestContext.getCurrentContext();
//        HttpServletRequest request = currentContext.getRequest();
//
//        // 权限验证
//        String token = request.getParameter("token");
//        if(!"admin".equals(token)){
//            String massage = "访问权限不足！";
//            log.warn(massage);
//            throw new RuntimeException(massage);
//        }

        // 转发
        return null;
    }
}
